let app = getApp()
Component({
    properties: {
        type:String,
        vueId: {
          type: Number,
          observer: function(newVal, oldVal) {
            this.updateRate()
          }
        }
      },
      data:{
       loginShow:false,
       flag: !1,
       settingShow: !1,
       selIndex: 0,
       wordsArr: [],
       class_id: "",
       wordsId: "",
       editCont: ""
      },
      pageLifetimes: {
        show: function () {
            this.get_data()
        }
      },
    lifetimes: {
        attached: function () {
         }
      },
    methods: {
      updateRate:function(){
         this.get_data()
      },
      chooseword:function(e){
        var word=e.currentTarget.dataset.word
        this.triggerEvent ('chooseword',word)
      },
      get_data:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Wordpool_wordList',
            staff_id:wx.getStorageSync('staff_bind_id'),
          },
          success: function(res) {
             that.setData({
              wordsArr:res.data.info,
              class_id:res.data.info[0].class_id
             })
          }
        })
      },
      editdo:function(e){
        this.setData({
          settingShow:false
        })
        wx.navigateTo({
          url: '/business-service/pages/staff_wordsManage/addWords?type=edit&id='+this.data.do_id+'&cont='+this.data.cont,
        })
      },
      deldo:function(e){
        this.setData({
          settingShow:false
        })
        var do_id=this.data.do_id
        var that=this
        wx.showModal({
          title: '提示',
          content: '确定要删除这条话术吗？',
          showCancel: true,
          cancelText:"取消",
          confirmText:"确定",
          success: function (res) {
            if (res.cancel) {
            } else{
              wx.request({
                url: app.globalData.siteroot,
                data: {
                  do:'Wordpool_delWord',
                  staff_id:wx.getStorageSync('staff_bind_id'),
                  id:do_id
                },
                success: function(res) {
                   that.get_data();
                }
              })
            }
           },
           fail: function (res) { },
           complete: function (res) { }
      })
      },
      cancel:function(e){
        this.setData({
          settingShow:false
        })
      },
      changeclass:function(e){
           this.setData({
              class_id:e.currentTarget.dataset.id,
              selIndex:e.currentTarget.dataset.index
          })
      },
      editdele:function(e){
        var id=e.currentTarget.dataset.id;
        var cont=e.currentTarget.dataset.cont;
        this.setData({
          do_id:id,
          cont:cont,
          settingShow:true
        })
      },
      addWords:function(){
        wx.navigateTo({
          url: '/business-service/pages/staff_wordsManage/addWords?type=add&id='+this.data.class_id+'&cont=',
        })
      }
    }
});
